var studentAttendenceChart = echarts.init(document.getElementById('studentAttendence'));
var studentNonAttendenceChart = echarts.init(document.getElementById('studentNonAttendence'));
var option2 = {
    title:{
        text: "近七日学生到课率情况",
        x:'center'
    },
    tooltip: {
        trigger: 'item',
        formatter: "{a} <br/>{b}: {c}% )",
        axisPointer: {
            type: 'shadow'
        }
    },
    toolbox: {
        show : true,
        feature : {
            mark : {show: true},
            dataView : {show: true, readOnly: false},
            restore : {show: true},
            saveAsImage : {show: true}
        }
    },
    legend: {
        data:['护理学院','机械工程学院'],
        orient: 'vertical',
        x: 'left'
    },
    xAxis: {
        type: 'value',
        boundaryGap: [0, 0.01]
    },
    yAxis: {

        data:['巴西','印尼','美国','印度','中国','内蒙古','a','b','c','d','中国','内蒙古']
    },
    series: [
        {
            name:'到课率',
            type:'line',
            radius: ['50%', '70%'],
            avoidLabelOverlap: false,
            label: {
                normal: {
                    show: false,
                    position: 'center'
                },
                emphasis: {
                    show: true,
                    textStyle: {
                        fontSize: '30',
                        fontWeight: 'bold'
                    }
                }
            },
            labelLine: {
                normal: {
                    show: false
                }
            },
            data:[1, 23489, 29034, 104970, 0, 63030,63230,30230,63030,63230,63030,63230]
        }
    ]
};
function Percentage(num, total) {
    return (Math.round(num / total * 10000) / 100.00);// 小数点后两位百分比
}
var option3 = {
    title: {
        text: '近七日学生缺课情况',
        x:'center'
    },
    tooltip: {},
    toolbox: {
        show : true,
        feature : {
            mark : {show: true},
            dataView : {show: true, readOnly: false},
            restore : {show: true},
            saveAsImage : {show: true}
        }
    },
    legend: {
        data:['护理学院','机械工程学院'],
        x:'left'
    },
    xAxis: {
        axisLabel:{
            rotate: 30,
            interval:0
        },
        data: ['11-16','11-17','11-18','11-19','11-20','11-21']
    },
    yAxis: {},
    series: [{
        name: '护理学院',
        type: 'bar',
        data: [12,22,33,,55,22]
    },{
        name: '机械工程学院',
        type: 'bar',
        data: [19,22,34,40,57,21]
    }
    ]
};
function loadOption(data){
    $.ajax({
        url : baseURL + "/StudentCharts/studentAttendence",
        data : {
            "option":$("#option").val(),
            "datas":data
        },
        dataType : "json",
        success : function(result) {
            var list=result.list;
            var listall=result.allList;
            var datelist=result.datelist;
            var map=result.map;
            var map1=result.map1;
            option3.legend.data=[];
            option3.xAxis.data=[];
            option3.series=[];
            option2.yAxis.data=[];
            option2.series=[];
            option2.legend.data=[];
            for(var i=0;i<datelist.length;i++){
                option3.xAxis.data.push((datelist[i]));
                option2.yAxis.data.push((datelist[i]));
            }
            var i=0;
            for(var key in map){
                var newline='';
                if(i++%3==0) option3.legend.data.push(newline);
                option3.legend.data.push(key);
                option3.series.push(map[key]);
            }
            var i=0;
            for(var key in map1){
                var newline='';
                if(i++%3==0) option2.legend.data.push(newline);
                option2.legend.data.push(key);
                var x= {
                    normal: {
                        label: {
                            show: true,//是否展示
                            textStyle: {
                                fontWeight: 'bolder',
                                fontSize: '12',
                                fontFamily: '微软雅黑',
                            }
                        }
                    }
                }
                map1[key].itemStyle=x;
                option2.series.push(map1[key]);
            };
            //     option3.series[0].data.push(list[i].count);
            //     option2.yAxis.data.push(listall[i].date);
            //     var attendence=listall[i].count-list[i].count;
            //     option2.series[0].data.push(Percentage(attendence,listall[i].count));
            // }
            studentAttendenceChart.setOption(option2,true);
            studentNonAttendenceChart.setOption(option3,true);
        },
        error : function(errorMsg) {
            //请求失败时执行该函数
            alert("图表请求数据失败!");
            studentNonAttendenceChart.hideLoading();
        }

    })
};
$("#option").change(function () {
    document.getElementById("CollegeSelect").style.display="none";
    $("#multiSelect").empty();
    var option = $("#option").val();
    if (option == 'college') {
        $.ajax({
            url: baseURL + "/college/getAllStudentCollege",
            success: function (r) {
                $("#multiSelect").empty();
                $("#multiSelect").append("请选择学院<br/>");
                for (i = 0; i < r.list.length; i++) {
                    var tname = r.list[i].collegeName;
                    $("#multiSelect").append("<label><input type=\"checkbox\" name=\"multiSelect\" value=\"" + tname + "\" />" + tname + "</label>&nbsp&nbsp");
                }
            }
        });
    }else if(option == 'class'){
        document.getElementById("CollegeSelect").style.display=""
    }
});
$("#College").change(function () {
    $("#multiSelect").empty();
    var college = $("#College").val();
        $.ajax({
            url: baseURL + "/college/getClassByCollege",
            data: {
                college:college
            },
            success: function (r) {
                $("#multiSelect").empty();
                $("#multiSelect").append("请选择班级<br/>");
                for (i = 0; i < r.list.length; i++) {
                    var tname = r.list[i];
                    var tid = r.list[i];
                    $("#multiSelect").append("<label><input type=\"checkbox\" name=\"multiSelect\" value=\"" + tname + "\" />" + tname + "</label>&nbsp&nbsp");
                }
            }
        });
});
function query() {
    var obj=document.getElementsByName('multiSelect');
    var s='';
    for(var i=0; i<obj.length; i++){
        if(obj[i].checked)
            s+=obj[i].value+','; //如果选中，将value添加到变量s中
    }
   loadOption(s);
}
$(document).ready(function() {
    $.ajax({
        url: baseURL + "/college/getAllStudentCollege",
        data: {},
        success: function (r) {
            $("#College").append("<option value=''>请选择学院</option>");
            for (i = 0; i < r.list.length; i++) {
                var tname = r.list[i].collegeName;
                var tid = r.list[i].collegeName;
                $("#College").append("<option value='" + tid + "'>" + tname + "</option>");
            }
        }});
    // 使用刚指定的配置项和数据显示图表。
   //studentAttendenceChart.setOption(option2);
   loadOption('');
   // studentNonAttendenceChart.setOption(option3);
});